Message = {
	init:function(blockClass, titleClass, contentClass, actionClass, buttonClass, specialClass, buttonEvent){
		this.blockClass = blockClass;
		this.titleClass = titleClass;
		this.contentClass = contentClass;
		this.actionClass = actionClass;
		this.buttonClass = buttonClass;
		this.specialClass = specialClass;
		this.buttonEvent = buttonEvent;
		
		this.BUTTON_OK = new this.Button("確定", function(){Message.hide();});
		this.BUTTON_CANCEL = new this.Button("取消", function(){Message.hide();});
	},
	show:function(id, width, title, content, buttonLeft, buttonRight){
		if(document.getElementById(id)){
			return;
		}
		this.zIndex += 2;
		this.amount++;
		Message.stack.push(id);
		
		var instance = this.createInstance(id, width);
		this.createMask(id);
		this.createTitle(instance, title);
		this.createContent(instance, content);
		if(buttonLeft){
			this.createAction(id, instance, buttonLeft, buttonRight);
			document.getElementById(id + "-button-left").focus();
		}
	},
	hide:function(){
		var id = Message.stack.pop();
		document.body.removeChild(document.getElementById(id + "-block"));
		document.body.removeChild(document.getElementById(id + "-mask"));
		this.zIndex -= 2;
		this.amount--;
		
		if(Message.stack.length != 0){
			var button = document.getElementById(Message.stack[Message.stack.length - 1] + "-button-left");
			if(button){
				button.focus();
			}
		}
	},
	createInstance:function(id, width){
		var instance = Utility.createElement(
			"div", 
			{id:id + "-block", className:this.blockClass}, 
			{zIndex:this.zIndex + "", position:"fixed", width:width + "px",
			 top:"50%", left:"50%", marginTop:"-" + (width / 2) + "px", marginLeft:"-" + (width / 2) + "px"}, 
			null, document.body
		);
		return instance;
	},
	createMask:function(id){
		Utility.createElement(
			"div", 
			{id:id + "-mask"},
			{width:"100%", height:window.screen.availHeight + "px", backgroundColor:"black",
			 filter:"alpha(opacity=" + this.filter + ")", opacity:this.filter / 100 + "", 
			 zIndex:this.zIndex - 1 + "", position:"fixed", left:"0px", top:"0px"},
			null, document.body
		);
	},
	createTitle:function(instance, title){
		Utility.createElement(
			"div", 
			{id:"msg-title", className:this.titleClass, innerHTML:title}, 
			{textAlign:"center", width:"100%"}, 
			null, instance
		);
	},
	createContent:function(instance, cont){
		var content = Utility.createElement(
			"div", 
			{id:"msg-content", className:this.contentClass}, 
			{width:"100%"}, 
			null, instance
		);
		if(typeof(cont) == "object"){
			content.appendChild(cont);
		}else{
			content.innerHTML = cont;
		}
	},
	createAction:function(id, instance, buttonLeft, buttonRight){
		var action = Utility.createElement(
			"div",
			{id:"msg-button", className:this.actionClass},
			{width:"100%", clear:"both"},
			 null, instance
		);
		
		if(buttonLeft && buttonRight){
			var actionLeft = Utility.createElement(
				"div",
				{id:"msg-button-left-item"},
				{height:"100%", width:"50%", textAlign:"center", float:"left", cssFloat:"left"},
				null, action
			);
			var button = this.createButton(id + "-button-left", actionLeft, buttonLeft);
			var actionRight = Utility.createElement(
				"div",
				{id:"msg-button-right-item"},
				{height:"100%", width:"50%", textAlign:"center", float:"right", cssFloat:"right"},
				null, action
			);
			this.createButton(id + "-button-right", actionRight, buttonRight);
		}else if(buttonLeft){
			var actionLeft = Utility.createElement(
				"div",
				{id:"msg-button-left-item"},
				{height:"100%", width:"100%", textAlign:"center", float:"left", cssFloat:"left"},
				null, action
			);
			var button = this.createButton(id + "-button-left", actionLeft, buttonLeft);
		}
	},
	createButton:function(id, actionPart, button){
		var instance = Utility.createElement(
			"button", 
			{id:id, innerHTML:button.text, 
			 className:(button.isSpecial && this.specialClass) ? this.specialClass : this.buttonClass}, 
			null, null, actionPart
		);
		Utility.setAttr(instance, {onclick:button.eventClick});
		Utility.setAttr(instance, this.buttonEvent);
		Utility.setAttr(instance, button.attr);
		
		return instance;
	},
	zIndex:2,
	filter:60,
	amount:0,
	stack:new Array(0),
	
	Button:function(text, eventClick, isSpecial, attr){
		this.text = text;
		this.eventClick = eventClick;
		this.isSpecial = isSpecial;
		this.attr = attr;
	}
}